<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            margin-top: 50px;
            width: 200px;
            height: 200px;
            background-color: pink;
            text-align: center;
            line-height: 200px;
            font-size: 48px;
            display: none;
        }
    </style>
</head>

<body>
    <button>显示</button>
    <div class="box">盒子</div>

    <script>
        //需求：点击button,隐藏盒子。改变文字，在点击按钮，显示出来。
        //步骤：
        //1.获取事件源和相关元素
        //2.绑定事件
        //3.书写事件驱动程序

        let box = document.querySelector('.box')
        let btn = document.querySelector('button')
        btn.onclick = function () {
            if (this.innerHTML === '显示') {
                btn.innerHTML = '隐藏'
                box.style = ' display: block'
            }
            else {
                btn.innerHTML = '显示'
                box.style = ' display: none'
            }

        }
    </script>
</body>

</html>